package com.suray.wcs.service.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.suray.basic.wcs.utils.IBaseEnum;

import java.io.Serializable;

public enum TaskStatus implements IBaseEnum<Serializable> {
    /**
     * 任务新生成等待执行（指插入到数据库）
     */
    NEW(0, "新生成"),
    /**
     * 任务进入等待执行队列（指从数据库中取出排队）
     */
    WAIT(1, "等待执行中"),
    /**
     * 任务进行中
     */
    ON_GOING(2, "任务进行中"),

    /**
     * 任务完成
     */
    FINISH(3, "任务完成"),
    /**
     * 任务完成且提交WMS
     */
    COMMITTED(100, "已提交WMS"),
    /**
     * 任务取消
     */
    CANCEL(200, "任务取消"),
    /**
     * 任务错误
     */
    ERROR(500, "任务错误"),
    /**
     * 避让状态
     */
    AVOID(700, "避让状态");


    @EnumValue
    private int taskProgress;
    @JsonValue
    private String description;

    TaskStatus(int taskProgress, String description) {
        this.taskProgress = taskProgress;
        this.description = description;
    }

    @Override
    public String toString() {
        return description;
    }

    public static TaskStatus parseTaskProgress(int taskProgress) {
        TaskStatus[] taskProgresses = TaskStatus.values();
        for (TaskStatus progress : taskProgresses) {
            if (progress.taskProgress == taskProgress) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度参数异常");
    }

    public static TaskStatus getByTaskProgress(int taskProgress) {
        TaskStatus[] taskProgresses = TaskStatus.values();
        for (TaskStatus progress : taskProgresses) {
            if (progress.taskProgress == taskProgress) {
                return progress;
            }
        }
        throw null;
    }

    public static TaskStatus parseTaskProgress(String description) {
        TaskStatus[] taskProgresses = TaskStatus.values();
        for (TaskStatus progress : taskProgresses) {
            if (progress.description.equals(description)) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度描述异常");
    }

    public int getProgressNum() {
        return taskProgress;
    }

    @Override
    public Serializable getValue() {
        return taskProgress;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public Integer getVal() {
        // TODO Auto-generated method stub
        return null;
    }

}
